//状态机


import axios from '../../http/axios.js'
import { get } from '../../http/axios.js'

export default {
    //命名空间  快速定位
    namespaced: true,
    //状态data  存储变量
    state: {
        datalist: {}
    },
    //过滤器  处理stata中的变量
    getters: {
        confirmed(state) {
            console.log(state);
            
            if (state.datalist.list) {
                // console.log(state.datalist);
                var res=0;
                state.datalist.list.forEach((item) => {
                    // console.log(item);
                    res += item.confirmed;
                });
                // console.log(res);

            }
            return res;
        },
        suspected(state) {
            // console.log(state);
            
            if (state.datalist.list) {
                // console.log(state.datalist);
                var res=0;
                state.datalist.list.forEach((item) => {
                    // console.log(item);
                    res += item.suspected;
                });
                // console.log(res);

            }
            return res;
        },
        dead(state) {
            // console.log(state);
            
            if (state.datalist.list) {
                // console.log(state.datalist);
                var res=0;
                state.datalist.list.forEach((item) => {
                    // console.log(item);
                    res += item.dead;
                });
                // console.log(res);

            }
            return res;
        },
        cure(state) {
            // console.log(state);
            
            if (state.datalist.list) {
                // console.log(state.datalist);
                var res=0;
                state.datalist.list.forEach((item) => {
                    // console.log(item);
                    res += item.cure;
                });
                // console.log(res);

            }
            return res;
        },
        severe(state) {
            // console.log(state);
            
            if (state.datalist.list) {
                // console.log(state.datalist);
                var res=0;
                state.datalist.list.forEach((item) => {
                    // console.log(item);
                    res += item.severe;
                });
                // console.log(res);

            }
            return res;
        },
        outside(state) {
            // console.log(state);
            
            if (state.datalist.list) {
                // console.log(state.datalist);
                var res=0;
                state.datalist.list.forEach((item) => {
                    // console.log(item);
                    res += item.outside;
                });
                // console.log(res);

            }
            return res;
        }
    },
    //突变  改变state中变量的唯一方式
    mutations: {
        set_datalist(state, list) {

            state.datalist = list;
        }
    },
    //动作 methods  存储方法  发送请求
    actions: {
        async page_query(context, params) {
            console.log(212);
            
            let res = await get('/epidemic/pageQuery', params)
            // console.log(res.data.list);
            console.log(res.data.list);

            //把结果给突变里面的方法
            context.commit('set_datalist', res.data.data)

        }

    }
}